<?php
use common\modules\user\models\User;
use yii\db\Migration;

class m150913_192740_user_seed_data extends Migration
{
    public function safeUp()
    {
        $this->insert('{{%user}}', [
            'id' => 1,
            'username' => 'webmaster',
            'email' => 'webmaster@example.com',
            'password_hash' => Yii::$app->getSecurity()
                ->generatePasswordHash('webmaster'),
            'auth_key' => Yii::$app->getSecurity()
                ->generateRandomString(),
            'access_token' => Yii::$app->getSecurity()
                ->generateRandomString(),
            'source' => User::SOURCE_BACKEND,
            'status' => User::STATUS_ACTIVE,
            'created_at' => time(),
            'updated_at' => time()
        ]);
        $this->insert('{{%user}}', [
            'id' => 2,
            'username' => 'manager',
            'email' => 'manager@example.com',
            'password_hash' => Yii::$app->getSecurity()
                ->generatePasswordHash('manager'),
            'auth_key' => Yii::$app->getSecurity()
                ->generateRandomString(),
            'access_token' => Yii::$app->getSecurity()
                ->generateRandomString(),
            'source' => User::SOURCE_BACKEND,
            'status' => User::STATUS_ACTIVE,
            'created_at' => time(),
            'updated_at' => time()
        ]);
        $this->insert('{{%user}}', [
            'id' => 3,
            'username' => 'user',
            'email' => 'user@example.com',
            'password_hash' => Yii::$app->getSecurity()
                ->generatePasswordHash('user'),
            'auth_key' => Yii::$app->getSecurity()
                ->generateRandomString(),
            'access_token' => Yii::$app->getSecurity()
                ->generateRandomString(),
            'source' => User::SOURCE_FRONTEND,
            'status' => User::STATUS_ACTIVE,
            'created_at' => time(),
            'updated_at' => time()
        ]);
        
        $this->insert('{{%user_profile}}', [
            'user_id' => 1,
            'locale' => Yii::$app->language
        ]);
        $this->insert('{{%user_profile}}', [
            'user_id' => 2,
            'locale' => Yii::$app->language
        ]);
        $this->insert('{{%user_profile}}', [
            'user_id' => 3,
            'locale' => Yii::$app->language
        ]);        
    }

    public function safeDown()
    {      
        $this->delete('{{%user_profile}}', [
            'user_id' => [
                1,
                2,
                3
            ]
        ]);
        
        $this->delete('{{%user}}', [
            'id' => [
                1,
                2,
                3
            ]
        ]);
    }
}
